using System.ComponentModel.DataAnnotations;

namespace ETask.Api.Models
{
    /// <summary>
    /// 审计日志模型
    /// </summary>
    public class AuditLog : BaseEntity
    {
        /// <summary>
        /// 操作类型（登录、创建、更新、删除等）
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string ActionType { get; set; } = string.Empty;

        /// <summary>
        /// 操作模块（用户、项目、成员、文档等）
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string Module { get; set; } = string.Empty;

        /// <summary>
        /// 操作描述
        /// </summary>
        [Required]
        [MaxLength(500)]
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 操作者用户ID
        /// </summary>
        [Required]
        public int UserId { get; set; }

        /// <summary>
        /// 操作者用户名
        /// </summary>
        [MaxLength(100)]
        public string? UserName { get; set; } = string.Empty;

        /// <summary>
        /// 操作者账户
        /// </summary>
        [MaxLength(100)]
        public string? Account { get; set; } = string.Empty;

        /// <summary>
        /// 目标对象ID（如项目ID、用户ID等）
        /// </summary>
        public int? TargetId { get; set; }

        /// <summary>
        /// 目标对象名称（如项目名称、用户名等）
        /// </summary>
        [MaxLength(200)]
        public string? TargetName { get; set; } = string.Empty;

        /// <summary>
        /// 操作前的数据（JSON格式）
        /// </summary>
        public string? OldValues { get; set; }

        /// <summary>
        /// 操作后的数据（JSON格式）
        /// </summary>
        public string? NewValues { get; set; }

        /// <summary>
        /// 客户端IP地址
        /// </summary>
        [MaxLength(50)]
        public string? ClientIp { get; set; }

        /// <summary>
        /// 用户代理
        /// </summary>
        [MaxLength(500)]
        public string? UserAgent { get; set; }

        /// <summary>
        /// 操作结果（成功、失败）
        /// </summary>
        [MaxLength(20)]
        public string Result { get; set; } = "成功";

        /// <summary>
        /// 错误信息（如果操作失败）
        /// </summary>
        [MaxLength(1000)]
        public string? ErrorMessage { get; set; }

        /// <summary>
        /// 操作时间
        /// </summary>
        public DateTime ActionTime { get; set; } = DateTime.Now;
    }
}
